Position BinarySearch(List L, ElementType X) {
    int l = 0, r = L->Last;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (L->Data[mid] == X) {
            return mid;
        } else if (L->Data[mid] < X) {
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    return NotFound;
}